<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class route_fuel_list extends Page
{
       public $lbldispatch = null;
       public $Label1 = null;
       public $lblName = null;
       public $lblId = null;
       public $lblEmpName = null;
       public $lblEmpId = null;
       public $JSdelete = null;
       public $Image1 = null;
       public $imgBack = null;
       public $imgAdd = null;
       public $hfVehicle = null;
       public $hfRoute = null;
       public $hfEmployee = null;
       public $JTSiteTheme1 = null;
       public $JTFuelList = null;
       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back.png"
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgBack'].src="image/btn_back2.png"
       <?php

       }

       function imgAddJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new.png"
       <?php

       }

       function imgAddJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['imgAdd'].src="image/add_new_blue.png"
       <?php

       }
       function imgAddJSClick($sender, $params)
       {

       ?>
       var veh_id = document.getElementById('hfVehicle').value;
       var emp_id = document.getElementById('hfEmployee').value;
       var route_id = document.getElementById('hfRoute').value;
       document.location.href = 'route_fuel.php?emp='+emp_id+'&route='+route_id+'&veh='+veh_id;
       <?php

       }

       function JTFuelListShow($sender, $params)
       {
       $veh_id = $this->hfVehicle->getValue();
       $emp_id = $this->hfEmployee->getValue();
       $route_id = $this->hfRoute->getValue();

       $arr_rou_fuel = array();
       $query_rou_fuel = "SELECT * FROM rou_fuel_tbl WHERE route_id='".$route_id."'";
       $result_rou_fuel = mysql_query($query_rou_fuel) or die("SELECT ROUTE FUEL ".mysql_error());
       while($row_rou_fuel = mysql_fetch_array($result_rou_fuel))
       {
        $rfuel_id = $row_rou_fuel['rfuel_id'];
        $date = substr($row_rou_fuel['timestamp'],0,10);
        $brand = $row_rou_fuel['brand'];
        $price = $row_rou_fuel['price'];
        $gallons = $row_rou_fuel['gallons'];
        $tot_cost = $row_rou_fuel['tot_cost'];
        $tools = "<img src='image/delete.png' style='cursor:pointer' onclick='js_delete(".$rfuel_id.",".$veh_id.",".$emp_id.",".$route_id.")'></img>";

        $edit_date = "<a href='route_fuel_edit.php?rfuel_id=".$rfuel_id."&veh=".$this->hfVehicle->getValue()."&route=".$this->hfRoute->getValue()."&emp=".$this->hfEmployee->getValue()."'>".$date."</a>";

        $arr_rou_fuel[] = array(
        'Date' => $edit_date,
        'Brand' => $brand,
        'Price/Li' => $price,
        'Liters' => $gallons,
        'Total' => $tot_cost,
        'Tools' => $tools
        );
       }
       $this->JTFuelList->setCellData($arr_rou_fuel);
       }

       function route_fuel_listCreate($sender, $params)
       {
       $get_emp = $_GET['emp'];
       if($get_emp!='' && $get_emp!=null && isset($get_emp))
       {
        $this->hfEmployee->setValue($get_emp);
       }

       $get_route = $_GET['route'];
       if($get_route!='' && $get_route!=null && isset($get_route))
       {
        $this->hfRoute->setValue($get_route);
       }

       $get_vehicle = $_GET['veh'];
       if($get_vehicle!='' && $get_vehicle!=null && isset($get_vehicle))
       {
        $this->hfVehicle->setValue($get_vehicle);
       }

       $query1 = "select * from route_tbl where route_id='".$this->hfRoute->getValue()."'";
       $result = mysql_query($query1)or die(mysql_error());
       $row_route = mysql_fetch_array($result);

       $this->lbldispatch->Caption = $row_route['job_no'];

       $query_emp = "select * from employee_tbl where autoid='".$this->hfEmployee->getValue()."'";
       $result_emp = mysql_query($query_emp)or die(mysql_error());
       $row_emp = mysql_fetch_array($result_emp);

       $this->lblId->Caption=$row_emp['emp_id'];
       $this->lblName->Caption=$row_emp['lname'].','.$row_emp['fname'];

       $this->imgBack->setLink('route_list.php?emp='.$this->hfEmployee->getValue());
       }


}

global $application;

global $route_fuel_list;

//Creates the form
$route_fuel_list = new route_fuel_list($application);

//Read from resource file
$route_fuel_list->loadResource(__FILE__);

//Shows the form
$route_fuel_list->show();

?>